<template>
  <el-container class="home-container">
    <el-header>
      <!-- logo -->
      <img src="../../assets/logoheader.png" alt="" />

      <!-- 导航栏  @select="handleSelect" -->
      <!-- <el-menu :default-active="$route.path" class="el-menu-demo" style="width: 500px" mode="horizontal" background-color="rgba(0,21,41,0.4)" text-color="#fff" active-text-color="#ffd04b" router>
        <el-menu-item index="/teach/problem/questionList">
          <i class="el-icon-s-order"></i>
          <span class="ming">问题管理</span>
        </el-menu-item>
        <el-menu-item index="/teach/exam">
          <i class="el-icon-collection"></i>
          <span class="ming">考试管理</span>
        </el-menu-item>
        <el-menu-item @click="qwe">
            <i class="el-icon-s-claim"></i>
            <span class="ming" >成绩管理</span>
    </el-menu-item>
      </el-menu> style="width: 80vh"-->
      <el-menu :default-active="activePath" class="el-menu-demo"  mode="horizontal" background-color="rgba(0,21,41,0.4)" text-color="#fff" active-text-color="#ffd04b" router>
        <el-menu-item :index="'/'+item.path" v-for="item in subItem" :key="item.id" @click="saveNavState('/' + item.path)">
        <template slot="title">
          <!-- <i :class="iconsObj[item.id]"></i> -->
          <span class="ming">{{item.anthname}}</span>
        </template>
        </el-menu-item>
      </el-menu>
      <!-- 用户显示信息 -->
      <div class="user">
        <img src="../../assets/pic.jpg" alt="" class="pic" />
        <el-dropdown>
<p class="username">西门吹雪</p>
  <el-dropdown-menu slot="dropdown">
    <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
  </el-dropdown-menu>
</el-dropdown>
      </div>
    </el-header>
    <el-main>
      <router-view></router-view>
    </el-main>
  </el-container>
</template>

<script>
export default {
  created () {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  // mounted () {
  //   this.activePath = '/teach/problem/questionList'
  // },
  data () {
    return {
      iconobj: {
        '01': 'el-icon-s-order',
        '02': 'el-icon-collection',
        '03': 'el-icon-s-claim'
      },
      subItem: [
        {
          id: '01',
          path: 'teach/problem/questionList',
          anthname: '问题管理'
        },
        {
          id: '02',
          path: 'teach/exam',
          anthname: '考试管理'
        },
        {
          id: '03',
          path: 'teach/grade',
          anthname: '成绩管理'
        }

      ],
      activePath: ''
    }
  },
  methods: {
    logout () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    // 保存链接的激活状态
    saveNavState (activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  },
  watch: {
    '$route.path': {
      immediate: true,
      handler (to, from) {
        console.log(this.activePath)
        console.log(to, 'to')
        console.log(from, 'from')
        console.log(location.hash, 'location.hash')
        this.activePath = to
        console.log(this.activePath)
      }
    }
  }
}
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
  width: 100%;
}
.el-header {
  background: rgb(0, 21, 41);
  height: 8.75vh!important;
  display: flex;
  justify-content: space-around;
}
.el-menu{
  display: flex;
  justify-content: center;
  align-content: center;
}
.el-menu-item{
    margin:0 0.625vh;
    height: 8.75vh!important;
}
.el-submenu__title:hover, .el-menu-item:focus, .el-menu-item:hover{
background-color: rgba(169, 177, 181, 0.5)!important;
}
.ming{
  display: inline-block;
  margin-top: 1vh;
  font-size: 2.5vh;
}
/* 显示用户信息 */
.pic {
  width: 6.25vh;
  height: 6.25vh;
  border-radius: 50%;
  /* padding-top: 8px; */
}
.user {
  display: flex;
  justify-content: center;
  align-content: center;
  padding-top: 0.625vh;
}
.user img {
  text-align: center;
}
.username {
  display: inline-block;
  padding-top: 2.375vh;
  color: white;
  padding-left: 1.25vh;
}
</style>
